package com.frame.platform.rank;

import com.frame.database.PageResult;
import com.frame.pageform.*;
import com.frame.pageform.annotation.Login;
import com.frame.pageform.component.JsonObject;
import com.frame.util.Pagination;

@Login
public class RankPage extends DataPageForm{

	static{
		initForward("/platform/rank/rank.page");
	}
	private String rankId;
	private String actions;
	private Wfrank bean;
	private String rankName;
	private String state;
	private String menuIds;

	public String execute() throws Exception {
		if("updateShow".equals(getActions())){
			setActions("update");
			RankDao dao=new RankDao();
			bean=dao.getRank(new Integer(getPrimaryKey_()[0]));
			return forward("add");
		}
		else if("update".equals(getActions())){
			RankDao dao=new RankDao();
			dao.updateRank(getBean());
			if(getMenuIds()!=null && !"".equals(getMenuIds())){
				String[] ids=getMenuIds().split("\\,");
				dao.addRankMenu(ids, getBean().getRankid());
			}
			JsonObject jsonObj=new JsonObject();
			jsonObj.put("state", "updateok");
			return jsonObj.toString();
		}
		else if("addShow".equals(getActions())){
			setActions("add");
			RankDao dao=new RankDao();
			return forward("add");
		}
		else if("add".equals(getActions())){
			RankDao dao=new RankDao();
			Integer rankid=dao.addRank(getBean());
			if(getMenuIds()!=null && !"".equals(getMenuIds())){
				String[] ids=getMenuIds().split("\\,");
				dao.addRankMenu(ids, rankid);
			}
			getBean().setRankid(null);
			JsonObject jsonObj=new JsonObject();
			jsonObj.put("state", "addok");
			return jsonObj.toString();
		}
		else if("del".equals(getActions())){
			if(getPrimaryKey_()!=null)
				new RankDao().delRank(getPrimaryKey_());
			initData();
		}
		else if("search".equals(getActions())){
			initData();
		}
		else{
			initData();
		}
		return forward();
	}

	private void initData() throws Exception{
		PageResult ps=new RankDao().getRankList(getRankName(),getPageSize_(),getPageNum());
		setResultList_(ps.getList());
		setActions("");
		Pagination pageing=new Pagination(ps.getPageSize(),ps.getPageNo(),ps.getPageCount(),getResultList_().size(),ps.getResultCount());
		setPagination(pageing);
	}

	public String getActions() {
		return actions;
	}

	public void setActions(String actions) {
		this.actions = actions;
	}

	public Wfrank getBean() {
		return bean;
	}


	public void setBean(Wfrank bean) {
		this.bean = bean;
	}


	public String getRankName() {
		return rankName;
	}


	public void setRankName(String rankName) {
		this.rankName = rankName;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}


	public String getRankId() {
		return rankId;
	}

	public void setRankId(String rankId) {
		this.rankId = rankId;
	}

	@Override
	public String show() throws Exception {
		// TODO Auto-generated method stub
		return "";
	}

	@Override
	public boolean toUpdate() throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String toDel() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public String getMenuIds() {
		return menuIds;
	}

	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}

}
